var prefix = ctx + "${model.modulePackage}/${model.modelL}"

$(function() {
	var columns = [{
            checkbox: true
        },
#foreach($field in $fieldList)
#if($field.listShow == true)
#if($field.inputType == "select"&&${field.inputValueTwo} != "")
		{
			field : '${field.inputValueOneL}.${field.inputValueTwoL}', 
			title : '${field.comment}' 
		},
#elseif($field.inputType == "select"&&${field.inputValueTwo} == "")
		{
			field : 'sysDictData${velocityCount}.dictLabel', 
			title : '${field.comment}' 
		},
#elseif($field.inputType == "date")
		{
			field : '${field.field}', 
			title : '${field.comment}',
			formatter : function(value, row,index) {
					var str = "";
					 str +=value.substring(0,10);
						 return str;
				}
		},
#else
		{
			field : '${field.field}', 
			title : '${field.comment}' 
#if(${field.inputType}=="radio")
			,
            formatter: function(value, row, index) {
                if (value == '0') {
                    return '<span class="badge badge-primary">正常</span>';
                } else if (value == '1') {
                    return '<span class="badge badge-danger">禁用</span>';
                }
            }
#end
		},
#end
#end
#end
        {
            title: '操作',
            align: 'center',
            formatter: function(value, row, index) {
            	var actions = [];
            	actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="#" onclick="detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详细</a> ');
				actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
				actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
				return actions.join('');
            }
        }];
	var url = prefix + "/list";
	$.initTableParams(columns, url,queryParams);
});
/*搜索*/
function search() {
    $('.bootstrap-table').bootstrapTable('refresh', queryParams);
}

function queryParams(params) {
	return {
		// 传递参数查询参数
		pageSize:       params.limit,
		pageNum:        params.offset / params.limit + 1,
		searchValue:    params.search,
		orderByColumn:  params.sort,
		isAsc:          params.order,
#foreach( $field in $fieldList )
#if(${field.matchType}=="any"||${field.matchType}=="eq"||${field.matchType}=="left"||${field.matchType}=="right")
		${field.field}:$("#${field.field}").val(),
#elseif(${field.matchType}=="select")
		${field.field}:$("#${field.field} option:selected").val(),
#elseif(${field.matchType}=="numberRange")
		${field.field}Start:$("#${field.field}Start").val(),
		${field.field}End:$("#${field.field}End").val(),
#elseif(${field.matchType}=="dateRange")
		${field.field}Start:$("#${field.field}Start").val(),
		${field.field}End:$("#${field.field}End").val(),
#end
#end
	};
}
/*${model.comment}-详细*/
function detail(id) {
    var url = prefix + '/detail/' + id;
    layer_showAuto("${model.comment}详细", url);
}

/*${model.comment}-新增*/
function add() {
    var url = prefix + '/add';
    layer_showAuto("新增${model.comment}", url);
}

/*${model.comment}-修改*/
function edit(id) {
    var url = prefix + '/edit/' + id;
    layer_showAuto("修改${model.comment}", url);
}

// 单条删除
function remove(id) {
	$.modalConfirm("确定要删除选中${model.comment}吗？", function() {
		_ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("id");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", modal_status.WARNING);
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', { "ids": rows }, "post");
	});
}
